<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>面向对象编程</title>
	<!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
</head>
<body>
<script>
	//JavaScript不区分类和实例的概念 通过 prototype 来实现面向对象编程(原型)；
	let person = {
		name:'person',
		height:1.6,
		run:function () {
			console.log(this.name + " is running!");
		}
	};
	person.run();

	/**
	 * JavaScript的原型链和java的Class区别就在于，
	 * JavaScript没有Class的概念，所有对象都是实例，
	 * 所谓的继承只不过是把一个对象的原型指向另一个对象
	 */
	let xiaoming = {
		name:'xiaoming'
	};
	xiaoming.__proto__ = person;
	xiaoming.run();

	let bird = {
		fly:function () {
			console.log(this.name + " is fly!");
		}
	};

	xiaoming.__proto__ = bird;
	xiaoming.fly();

	/**
	 * 在实际的使用过程中不要随意的改变对象的__proto__属性，
	 * 我们可以通过Object.create()方法创建一个基于原型的对象,
	 * 但是新的对象没有任何的属性
	 */

	let teacher = {
		name:'老师',
		school:'2 Middle School',
		age:29,
		teaching:function () {
			console.log(this.name + "正在教书!");
		}
	};

	function createXiaohong(name) {
		var xiaohong = Object.create(teacher);
		xiaohong.name = name;
		return xiaohong;
	}
	var xiaohong = createXiaohong("小红");
	xiaohong.teaching();
	console.log("xiaohong.shcool:" + xiaohong.school);
</script>
</body>
</html>